import 'dart:convert' as convert;
import 'package:http/http.dart' as http;

//final String path = 'https://zygc.huizukeji.cn/takePhone';
final String path = 'http://192.168.31.79:8084/takePhone';


Future<dynamic> getLogin(String name, String pass, String regisId) async{
  print(name);
  print(pass);
  var pass1 = convert.utf8.encode(pass);
  var pass2 = convert.base64Encode(pass1);
  String url = path + '/login?userName=$name&password=$pass2&regisId=$regisId';
  var res = await http.get(url);
  String body = res.body;
  //解析json数据
  var json = convert.jsonDecode(body);
  return json;
}

Future<List<dynamic>> getListData(String status, String userId, int offset, int limit) async{
  String url = path + '/getTask?status=$status&takeawayId=$userId&limit=$limit&offset=$offset';
  var res = await http.get(url);
  String body = res.body;
  //解析json数据
  var json = convert.jsonDecode(body);
  return json;
}

Future updateStatus(String status, String orderId, String id) async{
  String url = path + '/updateStats?status=$status&id=$orderId&orderId=$id';
  var res = await http.post(url);
  String body = res.body;
  //解析json数据
  var json = convert.jsonDecode(body);
  return json;
}

Future addOrder(String orderId, String takeawayId) async{
  String url = path + '/addOrder?orderId=$orderId&takeawayId=$takeawayId';
  var res = await http.post(url);
  String body = res.body;
  //解析json数据
  var json = convert.jsonDecode(body);
  return json;
}

Future addPosition(double longitude, double latitude, String id) async{
  String url = path + '/addPosition?longitude=$longitude&latitude=$latitude&id=$id';
  var res = await http.post(url);
  String body = res.body;
  //解析json数据
  var json = convert.jsonDecode(body);
  return json;
}

Future getTaskById(String orderId) async{
  String url = path + '/getTaskById?orderId=$orderId';
  var res = await http.get(url);
  String body = res.body;
  //解析json数据
  var json = convert.jsonDecode(body);
  return json;
}